local s11__zhanshen = fk.CreateSkill {
  name = "s11__zhanshen",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["s11__zhanshen"] = "战神",
  [":s11__zhanshen"] = "锁定技，准备阶段，你选择一项未获得过的效果，获得此效果直到本局游戏结束：<br>" ..
      "1.摸牌阶段，你多摸一张牌；<br>" ..
      "2.你使用【杀】造成伤害+1；<br>" ..
      "3.你使用【杀】可以额外选择一个目标；<br>" ..
      "4.出牌阶段，你可以多出一张【杀】。",

  ["#s11__zhanshen-choice"] = "战神：选择一项效果，本局游戏永久获得",
  ["s11__zhanshen_1"] = "摸牌阶段多摸一张牌",
  ["s11__zhanshen_2"] = "使用【杀】伤害+1",
  ["s11__zhanshen_3"] = "使用【杀】可以额外选择一个目标",
  ["s11__zhanshen_4"] = "出牌阶段可以多出一张【杀】",
  ["@s11__zhanshen_1"] = "摸牌",
  ["@s11__zhanshen_2"] = "加伤",
  ["@s11__zhanshen_3"] = "分叉",
  ["@s11__zhanshen_4"] = "多杀",
  ["#s11__zhanshen-choose"] = "战神：你可以为此%arg增加一个目标",

  ["$s11__zhanshen1"] = "战神降世，神威再临！",
  ["$s11__zhanshen2"] = "战神既出，谁与争锋！",
}

s11__zhanshen:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(s11__zhanshen.name) and player.phase == Player.Start then
      for i = 1, 4 do
        if player:getMark("s11__zhanshen_" .. i) == 0 then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = table.map(table.filter({ 1, 2, 3, 4 }, function(n)
      return player:getMark("s11__zhanshen_" .. n) == 0
    end), function(n)
      return "s11__zhanshen_" .. n
    end)
    local choice = room:askToChoice(player, {
      choices = choices,
      skill_name = s11__zhanshen.name,
      prompt = "#s11__zhanshen-choice",
    })
    room:setPlayerMark(player, choice, 1)
    -- 添加可见标记，在游戏界面上显示选择的效果
    local choiceNumber = string.sub(choice, -1) -- 获取选项字符串的最后一个字符，即数字
    room:setPlayerMark(player, "@s11__zhanshen_" .. choiceNumber, 1)
  end,
})

s11__zhanshen:addEffect(fk.DrawNCards, {
  anim_type = "drawcard",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("s11__zhanshen_1") > 0
  end,
  on_use = function(self, event, target, player, data)
    data.n = data.n + 1
  end,
})

s11__zhanshen:addEffect(fk.PreCardUse, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("s11__zhanshen_2") > 0 and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    data.additionalDamage = (data.additionalDamage or 0) + 1
  end,
})

s11__zhanshen:addEffect(fk.AfterCardTargetDeclared, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("s11__zhanshen_3") > 0 and data.card.trueName == "slash" and
        #data:getExtraTargets() > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      targets = data:getExtraTargets(),
      min_num = 1,
      max_num = 1,
      prompt = "#s11__zhanshen-choose:::" .. data.card:toLogString(),
      skill_name = s11__zhanshen.name,
    })
    if #tos > 0 then
      room:sortByAction(tos)
      event:setCostData(self, { tos = tos })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    for _, p in ipairs(event:getCostData(self).tos) do
      data:addTarget(p)
    end
  end,
})

s11__zhanshen:addEffect("targetmod", {
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("s11__zhanshen_4") > 0 and scope == Player.HistoryPhase then
      return 1
    end
  end,
})

return s11__zhanshen
